﻿/**
*居间合同输入
*/
Chenxin.UI.DataEditForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: '/service/logic/ShowListIntent.ashx',
    id: 'InputInfo',
    renderTo: 'divEditInfo',
    winCls: '',
    jqmWidth: 650,
    defBBtn: true,
    createForm: function() {
        return Chenxin.FormCommon.DataEditForm(this.id);
    },
    initEvent: function() {
        var _this = this;
        var thisid = '#' + this.id;
        _this.isclick = true;

        $(thisid + '_save').live('click', function() {
            if (_this.isclick) {
                _this.save();
            }
        });
        $(thisid + '_cancle').live('click', function() {
            _this.hide();
        });
        $('#btn_gethouse_edit').live('click', function() {
            _this.getHouseInfo();
        });
    },
    getHouseInfo: function() {
        var _this = this;
        var _code = this.findByName('HouseCode').val();
        if (!_code) {
            alert('请输入房源编号！');
            return;
        }
        Chenxin.Msg.Waiting.show();
        Chenxin.ajax({
            type: "post",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: '/service/logic/ShowListIntent.ashx',
            data: { op: 'gethouse', housecode: _code, IntentionCode: this.findByName('IntentionCode').val() },
            onSuccess: function(data, msg) {
                Chenxin.Msg.Waiting.hide();
                if (data) {
                    _this.findByName('HouseId').val(data.HouseId);
                    _this.findByName('HouseCode').val(data.HouseCode);
                    _this.findByName('HouseAddress').val(data.HouseAddress);
                    _this.findByName('CustomerName_Sale').val(data.CustomerName_Sale);
                    _this.findByName('TotalPrice').val(data.TotalPrice);
                    _this.findByName('Region').setValeByText(data.Region);
                }
            },
            onFail: function() {
                Chenxin.Msg.Waiting.hide();
            },
            onWrong: function() {
                Chenxin.Msg.Waiting.hide();
            },
            onError: function() {
                Chenxin.Msg.Waiting.hide();
            }
        });
    },
    initFormValidator: function() {
        //物件地址
        $('#' + this.id + '_HouseAddress_edit').formValidator({
            validatorgroup: this.id,
            onshow: "请输入地址！",
            onfocus: "请输入地址！",
            oncorrect: "输入正确！"
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "地址不能为空！"
            },
            onerror: "地址不能为空！"
        });
        //房屋价格
        $('#' + this.id + '_TotalPrice_edit').formValidator({
            validatorgroup: this.id,
            onshow: "请输入房屋价格！",
            onfocus: "请输入房屋价格！",
            oncorrect: "输入正确！"
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "房屋价格不能为空！"
            },
            onerror: "房屋价格不能为空！"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                val = Chenxin.Fn.fullToHalfChar(val);
                if (parseInt(val) < 0) {
                    return false;
                }
                else {
                    return val.isNum();
                }
            },
            onerror: "请输入非0的数字"
        });
        //客户姓名
        $('#' + this.id + '_CustomerName_Buy_edit').formValidator({
            validatorgroup: this.id,
            onshow: "请输入客户！",
            onfocus: "请输入客户！",
            oncorrect: "输入正确！"
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "客户不能为空！"
            },
            onerror: "客户不能为空！"
        });
    },
    createComboList: function() {
        var region = new Chenxin.UI.ParameterCombo({
            name: 'Region',
            containerId: '#' + this.id + '_region_edit',
            key: 'System.Region',
            tbxWidth: 129,
            autoLoad: false,
            inModelType: 'txt'
        });

        return [region];
    },
    saveSucc: function() {
        this.reloadGrid();
    },
    initComponent: function() {
        Chenxin.UI.DataEditForm.superclass.initComponent.call(this);
    }
});

Chenxin.FormCommon.DataEditForm = function(formID) {
return '<table class="tbl_f"><tr><th style="width:100px;"><span id="span_codelabel">居间合同编号</span>：</th><td><input type="hidden"  name="IntentionId" /><input type="hidden"  name="HouseId" /><input type="text" name="IntentionCode" readonly="readonly" class="inputbox_n fl"  style="width:160px;"/></td><th style="width:100px;">领取业务员：</th><td><input type="text" name="LastEmployee" readonly="readonly" class="inputbox_n fl" style="width:160px;"/></td></tr><tr><th>建档日期：</th><td><input type="text" name="CreateDate" readonly="readonly" class="inputbox_n fl"  style="width:160px;"/></td><th>资料建档人员：</th><td><input type="text" name="CreateEmp" readonly="readonly" class="inputbox_n fl"  style="width:160px;"/></td></tr><tr><th>意向类型：</th><td colspan="3"><input type="text" readonly="readonly" class="inputbox_n fl"  style="width:160px;" name="IntentionType" /></td></tr><tr><th >房源编号：</th><td colspan="3"><input type="text" name="HouseCode" class="inputbox_n fl" style="width:160px;"/><input type="button" id="btn_gethouse_edit" value="获取房源信息" style="margin-left:10px;" title="获取房源信息"/></td></tr><tr><th>物件地址：</th><td colspan="3"><input type="text" id="' + formID + '_HouseAddress_edit" name="HouseAddress" class="inputbox_n fl" style="width:250px;"/><div id="' + formID + '_HouseAddress_editTip" style="margin-left: 5px; width: 120px; float:left;text-align: left;" class="fl"></div></td></tr><tr><th>区域:</th><td><div id="' + formID + '_region_edit" style="z-index:1; margin-right: 2px;" class="SelectWrapSingle"></div></td></tr><tr><th>房屋价格：</th><td colspan="3"><input type="text" id="' + formID + '_TotalPrice_edit"  class="inputbox_n fl"  style="width:160px;" name="TotalPrice" /><div id="' + formID + '_TotalPriceTip_edit" style="margin-left: 5px; width: 120px; float:left;text-align: left;" class="fl"></div></td></tr><tr><th>房东姓名：</th><td><input type="text" name="CustomerName_Sale" class="inputbox_n fl"  style="width:160px;" /></td></tr><tr><th>客户姓名：</th><td colspan="3"><input type="text" id="' + formID + '_CustomerName_Buy_edit" name="CustomerName_Buy"  class="inputbox_n fl"  style="width:160px;"/><div id="' + formID + '_CustomerName_Buy_editTip" style="margin-left: 5px; width: 120px; float:left;text-align: left;" class="fl"></div></td></tr><tr><th>首笔诚意金金额：</th><td colspan="3"><input type="text" id="' + formID + '_FirstMoney_edit" name="FirstMoney" class="inputbox_n fl" readonly="readonly"  style="width:160px;"/></td></tr><tr id="tr_emoney"><th>诚意金转为：</th><td colspan="3"><input type="radio" value="10" name="DeliverTo" id="housefund" /><label for="housefund">房款</label><input type="radio" value="20" name="DeliverTo" id="earnest"/><label for="earnest">定金</label></td></tr><tr><th>截止签约日期：</th><td><input type="text" class="inputbox_n fl"  style="width:160px;" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});" readonly="readonly" name="LastContractDate" /></td><th>转定/房款期限：</th><td><input type="text" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});" name="LastDeliverMoneyDate" readonly="readonly" class="inputbox_n fl" style="width:160px;" /></td></tr></table>';
};